function keyword(config) {
    var selector = config.ele || ".keyword"
    var container = config.box?document.querySelector(config.box):document
    var keywords = container.querySelectorAll(selector)
    for(var i = 0;i < keywords.length;i++){
        var item = keywords[i];
        item.classList.add(".keyword")
        var keybox = document.createElement("div")
        var target = document.createElement("input")
        target.type = "hidden"
        item.appendChild(keybox)
        keybox.appendChild(target)
        keybox.classList.add("keyword-box")
        var inputBox = document.createElement("input")
        item.appendChild(inputBox)
        inputBox.classList.add("keyword-input")
        target.setAttribute("name",item.getAttribute("name"))
        var defaultVal = item.getAttribute("value")
        if(defaultVal != undefined) {
            target.setAttribute("value",defaultVal)
            var spans = defaultVal.split(",")
            for(var i = 0;i < spans.length;i++) {
                var keySpan = document.createElement("span")
                keySpan.innerHTML = spans[i]
            }
        }


        inputBox.placeholder = "请输入关键字，支持空格或，或；隔开"

        inputBox.addEventListener("keyup",function(e) {
            if(e.keyCode == 188 || e.keyCode == 186) {
                var v = this.value
                if(v.length <= 1) {
                    this.value = ''
                    return
                }
                var keySpan = document.createElement("span")
                keySpan.innerHTML = v.substr(0, v.length - 1)
                keybox.appendChild(keySpan)
                if(target.value == "") {
                    target.value = v.substr(0,v.length - 1)
                }else {
                    var arr = target.value.split(",")
                    arr.push(v.substr(0,v.length - 1))
                    target.value = arr.join(',')
                }
                this.value = ''
            }
        })
        keybox.addEventListener("click",function(e){
            var str = e.target.innerText
            var arr = target.value.split(",")
            var ix = arr.indexOf(str)
            arr.splice(ix,1)
            target.value = arr.join(',')
            e.target.parentNode.removeChild(e.target)
        })
    }
}
